package com.shensi.adminCollect.controller.label;

import com.shensi.common.core.controller.BaseController;
import com.shensi.common.core.domain.AjaxResult;
import com.shensi.common.core.page.TableDataInfo;
import com.shensi.adminCollect.common.utils.poi.ExcelUtil;
import com.shensi.adminCollect.domain.label.CustomerLabelDemo;
import com.shensi.adminCollect.service.label.ICustomerLabelDemoHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

import com.shensi.common.core.domain.model.LoginUser;
import com.shensi.common.core.utils.SecurityUtils;

/**
 * 用户标签Controller
 *
 * @author qujia
 * @date 2021-06-15
 */
@RestController
@RequestMapping("/label/labelHistory")
@Api("LabelHistoryController")
public class CustomerLabelHistoryController extends BaseController
{

    @Autowired
    private ICustomerLabelDemoHistoryService customerLabelDemoHistoryService;



    /**
     * 查询标签用户
     */
    @GetMapping(value = "/selectCustomerLabelInfoList")
    @ApiOperation("查询标签用户")
    public TableDataInfo selectCustomerLabelInfoList(CustomerLabelDemo customerLabelDemo)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        //customerLabelDemo.setStationId(currentUser.getUser().getDeptId());
        //customerLabelDemo.setStationIdList(sysStationUserService.selectStationIdByEnterpriseId(currentUser.getUser().getEnterpriseId()));
        customerLabelDemo.setEnterpriseId(currentUser.getUser().getEnterpriseId());
        startPage();
        List<CustomerLabelDemo> list = new ArrayList<>();

         if(customerLabelDemo.getSecondFlag()!=null && customerLabelDemo.getSecondFlag().equals("1")) {
             if(customerLabelDemo.getEndCountNum()!=null&& customerLabelDemo.getEndCountNum()==0){
                 list=customerLabelDemoHistoryService.selectNewAppUser(customerLabelDemo);
             }else {
                 //开启二次查询
                 list = customerLabelDemoHistoryService.secondCustomerLabelDemoList(customerLabelDemo);
             }
        }else if(customerLabelDemo.getSecondFlag()!=null && customerLabelDemo.getSecondFlag().equals("0")) {
              if(customerLabelDemo.getEndCountNum()!=null&& customerLabelDemo.getEndCountNum()==0){
                  list=customerLabelDemoHistoryService.selectNewAppUser(customerLabelDemo);
              }else {
                  list = customerLabelDemoHistoryService.selectCustomerLabelDemoList(customerLabelDemo);
              }
         }

        return getDataTable(list);
    }


    /**
     * 导出用户标签列表
     */
    @GetMapping("/selectCustomerLabelInfoListExport")
    @ApiOperation("导出用户标签列表")
    public AjaxResult selectCustomerLabelInfoListExport(CustomerLabelDemo customerLabelDemo)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        //customerLabelDemo.setStationId(currentUser.getUser().getDeptId());
        //customerLabelDemo.setStationIdList(sysStationUserService.selectStationIdByEnterpriseId(currentUser.getUser().getEnterpriseId()));
        customerLabelDemo.setEnterpriseId(currentUser.getUser().getEnterpriseId());
//        customerLabelDemo.setPageSizeLimit(1000000);
        List<CustomerLabelDemo> list = new ArrayList<>();

        if(customerLabelDemo.getSecondFlag()!=null && customerLabelDemo.getSecondFlag().equals("1")) {
            if(customerLabelDemo.getEndCountNum()!=null&& customerLabelDemo.getEndCountNum()==0){
                list=customerLabelDemoHistoryService.selectNewAppUser(customerLabelDemo);
            }else {
                //开启二次查询
                list = customerLabelDemoHistoryService.secondCustomerLabelDemoList(customerLabelDemo);
            }
        }else if(customerLabelDemo.getSecondFlag()!=null && customerLabelDemo.getSecondFlag().equals("0")) {
            if(customerLabelDemo.getEndCountNum()!=null&& customerLabelDemo.getEndCountNum()==0){
                list=customerLabelDemoHistoryService.selectNewAppUser(customerLabelDemo);
            }else {
                list = customerLabelDemoHistoryService.selectCustomerLabelDemoList(customerLabelDemo);
            }
        }

        ExcelUtil<CustomerLabelDemo> util = new ExcelUtil<>(CustomerLabelDemo.class);
        return util.exportExcel(list, "label");
    }


}
